//
//  AY_SearchRecommChildCell.m
//  AiYue
//
//  Created by mac on 2023/11/9.
//

#import "AY_SearchRecommChildCell.h"

@interface AY_SearchRecommChildCell ()

@property (nonatomic, strong) UIImageView *icon;
@property (nonatomic, strong) UIImageView *bookImg;
@property (nonatomic, strong) UILabel *bookName;
@property (nonatomic, strong) UILabel *bookContent;
@property (nonatomic, strong) UILabel *indexLabel;

@end

@implementation AY_SearchRecommChildCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    
    if (self)
    {
        self.icon = [AYTool createImageViewWithFrame:CGRectZero andImage:nil andBg:nil andRadius:0 andAddSubView:self.contentView];
        [self.icon mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.contentView).offset(YNUM(18));
            make.centerY.equalTo(self.contentView);
            make.width.height.mas_equalTo(YNUM(26));
        }];
                
        self.bookImg = [AYTool createImageViewWithFrame:CGRectZero andImage:nil andBg:nil andRadius:YNUM(4) andAddSubView:self.contentView];
        [self.bookImg mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.icon.mas_right).offset(YNUM(10));
            make.width.mas_equalTo(YNUM(44));
            make.height.mas_equalTo(YNUM(58));
            make.centerY.equalTo(self.contentView);
        }];
        
        self.bookName = [AYTool createLabelWithFrame:CGRectZero andText:nil andTextColor:COLOR(@"010101") andBgColor:nil andFont:[UIFont boldSystemFontOfSize:YNUM(14)] andLines:1 andRadius:0 andAddSubView:self.contentView];
        [self.bookName mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.bookImg).offset(YNUM(2));
            make.left.equalTo(self.bookImg.mas_right).offset(YNUM(10));
            make.right.equalTo(self.contentView).offset(-YNUM(16));
        }];
        
        self.bookContent = [AYTool createLabelWithFrame:CGRectZero andText:nil andTextColor:COLOR(@"#BFBFBF") andBgColor:nil andFont:YFont(12) andLines:1 andRadius:0 andAddSubView:self.contentView];
        [self.bookContent mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.bookName.mas_bottom).offset(YNUM(5));
            make.left.equalTo(self.bookImg.mas_right).offset(YNUM(10));
            make.right.equalTo(self.contentView).offset(-YNUM(16));
        }];
    }
    return self;
}

- (void)setModel:(SearchModel *)model {
    self.bookName.text = model.title;
    [self.bookImg sd_setImageWithURL:[NSURL URLWithString:model.coverImg] placeholderImage:YImage(@"placeholderImage")];
    self.bookContent.text = model.info;
    NSString * topIndex = [NSString stringWithFormat:@"AY_search_%@", kStringUtils(model.index)];
    self.icon.image = YImage(topIndex);
    [self.indexLabel removeFromSuperview];
    if (model.index.integerValue < 3) {
        self.indexLabel = [AYTool createLabelWithFrame:CGRectZero andText:[NSString stringWithFormat:@"%ld",model.index.integerValue + 1] andTextColor:COLOR(@"#010101") andBgColor:nil andFont:YFont(10) andLines:1 andRadius:0 andAddSubView:self.icon];
        [self.indexLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(self.icon);
            make.centerY.equalTo(self.icon).offset(YNUM(5));
        }];
    }else {
        self.indexLabel = [AYTool createLabelWithFrame:CGRectZero andText:[NSString stringWithFormat:@"%ld",model.index.integerValue + 1] andTextColor:COLOR(@"#010101") andBgColor:nil andFont:[UIFont boldSystemFontOfSize:YNUM(16)] andLines:1 andRadius:0 andAddSubView:self.contentView];
        [self.indexLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.contentView).offset(YNUM(24));
            make.centerY.equalTo(self.contentView);
        }];
    }
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
